package org.jiajie.designpatterndemo.memento.lxf;

/**
 * 文本编辑器
 *
 * @author jay
 */
public class TextEditor {
    private StringBuilder buffer = new StringBuilder();

    public void add(char ch) {
        buffer.append(ch);
    }

    public void add(String s) {
        buffer.append(s);
    }

    public void delete(){
        if (buffer.length() > 0) {
            buffer.deleteCharAt(buffer.length() - 1);
        }
    }

    /**
     * 获取状态：
     */
    public String getState(){
        return buffer.toString();
    }

    /**
     * 恢复状态：
     */
    public void setState(String state){
        this.buffer.delete(0, this.buffer.length());
        this.buffer.append(state);
    }
}
